// pages/accountChange/accountChange.js
var app = getApp();
Page({

  /**
   * 
   * 页面的初始数据
   */
  data: {
    loadingHidden: true,
    detailedList: [],
    start_time: '', //开始时间
    end_time: '', //结束时间
    page: 1,
    page_count: 1,
    noMore: false,
    loading: false,
    row: 5,
    id: '',
    empty: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: options.id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getWapRecord();
  },


  getWapRecord: function () {
    var that = this;
    // that.setData({
    //   loadingHidden: false
    // })
    app.ajax({
      url: "Partner/Users/getWapRecord",
      data: {
        "page": that.data.page,
        "pageSize": that.data.row,
        "start_time": that.data.start_time,
        "end_time": that.data.end_time,
        "type": 1,
        "partner_id": that.data.id
      },
      success: function (res) {

        if (res.data.code == 1000) {

          var flag = res.data;
          // console.log(flag);
          if (flag.data.list.length != 0 && that.data.detailedList.length != 0) {
            if (that.data.detailedList[that.data.detailedList.length - 1].date == flag.data.list[0].date) {
              var tmp = that.data.detailedList;
              var same_time = tmp[tmp.length - 1].list.concat(flag.data.list[0].list);
              tmp[tmp.length - 1].list = same_time;
              that.setData({
                detailedList: tmp
              });
              flag.data.list.splice(0, 1);
            }
          }
          var list = that.data.detailedList.concat(res.data.data.list)
          var len = res.data.data.list.length;
          if (that.data.row > len) {
            that.setData({
              noMore: true
            })
          } else {
            that.setData({
              noMore: false
            })
          }

          that.setData({
            detailedList: list,
            page_count: res.data.data.count,
            empty: res.data.data.count == 0 ? true : false
          })

        }

        // if (res.data.code == -1000) {
        //   app.showToast('没有信息');
        //   return false;
        // }
        // if (res.data.data.list.length == 0) {
        //   app.showToast('没有更多了');
        // }
      }
    })
  },
  reachBottom: function () {
    var that = this;
    var page = that.data.page + 1;
    if (page > that.data.page_count) {
      that.setData({
        noMore: true
      })
      return false;
    }
    that.setData({
      page: page
    })
    that.getWapRecord();
  },

  //打开搜索弹窗
  search(e) {
    var that = this;
    that.setData({
      isSearch: true
    })
  },

  //点击搜索
  goSearch() {
    var that = this;
    that.setData({
      isSearch: false,
      detailedList: []
    })
    that.getWapRecord();
  },
  //返回搜索
  goBack() {
    var that = this;
    that.setData({
      isSearch: false
    })
  },
  //选择开始时间
  startTimeChange(e) {
    this.setData({
      start_time: e.detail.value
    })
  },
  //选择结束时间
  endTimeChange(e) {
    this.setData({
      end_time: e.detail.value
    })
  },

  //查看省略文字
  lookmore(e) {
    var jmz = {};
    jmz.GetLength = function (str) {
      return str.replace(/[\u0391-\uFFE5]/g, "a").length; //先把中文替换成两个字节的英文，在计算长度
    };
    if (jmz.GetLength(e.currentTarget.dataset.txt) >= 9) {
      app.showToast(e.currentTarget.dataset.txt);
    }
  },
  //查看省略文字
  lookmore(e) {
    var that = this;
    var jmz = {};
    jmz.GetLength = function (str) {
      return str.replace(/[\u0391-\uFFE5]/g, "a").length; //先把中文替换成两个字节的英文，在计算长度
    };
    if (jmz.GetLength(e.currentTarget.dataset.txt) >= 9) {
      that.setData({
        contdetail: e.currentTarget.dataset.txt,
        ispopshow: true
      });
    }

  },
  //关闭小黑窗户
  closeShow() {
    this.setData({
      ispopshow: false
    })
  },

})